package com.zheng.rpc;

import com.zheng.rpc.Impl.HelloServiceImpl;
import com.zheng.rpc.annotations.RpcScan;
import com.zheng.rpc.api.HelloService;
import com.zheng.rpc.entities.RpcServiceProperties;
import com.zheng.rpc.remoting.transport.netty.server.NettyRpcServer;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

@RpcScan(basePackage = {"com.zheng.rpc"})
public class NettyServerMain {
    public static void main(String[] args) {
        // Register service via annotation
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(NettyServerMain.class);
        NettyRpcServer nettyRpcServer = (NettyRpcServer) applicationContext.getBean("nettyRpcServer");
        // Register service manually
        HelloService helloService = new HelloServiceImpl();
        RpcServiceProperties rpcServiceProperties = RpcServiceProperties.builder()
                .group("test").version("v1.0").build();
        nettyRpcServer.registerService(helloService, rpcServiceProperties);
        nettyRpcServer.start();
    }
}